import { sys, view } from "cc";
import UrlEnum from "../Res/UrlEnum";
import Http, { IHttpMethod } from "../Net/Http";
import SdkInterface from "./SdkInterface";
import SdkTool from "./SdkTool";
import { ViewManager } from "../../Game/module/base/ViewManager";
import { SocketManager } from "../../Game/module/socket/SocketManager";
import TimerMgr from "../Timer/TimerMgr";
export default class BaseSdk implements SdkInterface {
    /**
     * 初始化
     * @param callback 初始化成功后回调
     * @param target 监听对象
     */
    public init(callback: Function, target: Object): void {
        console.log("BaseSdk init");
        SdkTool.ins.sidebar = true;
        SdkTool.ins.isSidebar = false;
    }

    /**
     * 登录
     * @param callback 登录成功后回调
     * @param target 监听对象
     */
    public login(): void {
        console.log("BaseSdk login");
        //{"openid":"${SdkTool.ins.openid}"}
        Http.ins.request(`${UrlEnum.httpUrl}Web/s1001/login.php?openid=${SdkTool.ins.openid}`, ``, (data) => {
            const info = JSON.parse(data);
            console.log(`Web/s1001/login.php`, info);
            SocketManager.ins.connect();
            SdkTool.ins.isFirst = info == 1;
        }, IHttpMethod.GET);
    }
    /**
     * 登出
     */
    public logout(): void {
        console.log("BaseSdk logout");
    }

    /**
     * 退出
     */
    public exit(): void {
        console.log("BaseSdk exit");
    }

    /**
     * 切换账号
     */
    public switchLogin(): void {
        console.log("BaseSdk switchLogin");
    }

    /**
     * 数据上报
     * @param param 参数
     */
    public report(...param: any[]): void {
        console.log("BaseSdk report");
    }

    /**
     * 数据上报
     * @param param 参数
     */
    public pay(...param: any[]): void {
        console.log("BaseSdk pay");
    }

    /**
     * 播放广告
     */
    createRewardAd(): void {
    }
    /**
     * 播放广告
     */
    playRewardAd(callback: Function, target: any): void {
        ViewManager.ins.showloading();
        TimerMgr.ins.add(2000, 1, () => {
            ViewManager.ins.removeLoading();
            callback.call(target, true);
        }, this);
    }
    /**
     * 显示banner广告
     */
    showBannerAd(show: boolean): void {
    }
    /**
     * 显示插屏广告
     */
    showInterstitialAd(): void { }
    /**
     * 显示自定义广告
     */
    showCustomAd(show, top?, left?): void { }
    /**
     * 主动拉起转发(小程序)
     */
    shareAppMessage(title: string, imageUrlId: string, imageUrl: string, query: any = null, shareCallback: any = null): void {
        if (shareCallback) {
            shareCallback();
        }
    }
    getAppParam(): any {
        return ``;
    }
    reconnect(): void {
        ViewManager.ins.showtips(`已掉线，正在重新连接...`);
        this.login();
    }
    public navigateToScene(): void {
        SdkTool.ins.isSidebar = true;
    }
    public getMenuButtonBoundingClientRect(): any {
        SdkTool.ins.topmenu = 0;
    }
    public setImRankData(val): void {

    }
    public getImRankList(): void {
        ViewManager.ins.showtips(`当前平台不支持排行榜`);
    }
    public vibrateShort(): void {

    }
}